package groupb6.shopsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import groupb6.shopsystem.pojo.entity.Product;
import groupb6.shopsystem.pojo.form.AddProductForm;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {
    /**
     * 上架商品
     * 待上架的商品信息
     * @param
     */
    @Select("select * from tb_product where id = #{productId};")
    Product getProductById(Integer productId);

    @Select("select * from tb_product where id = #{productId};")
    Product getProductByOrderId(Integer orderId);

    @Select("SELECT * FROM tb_product WHERE seller_id = #{sellerId};")
    List<Product> getProductsBySellerId(Integer sellerId);
    @Insert("INSERT INTO tb_product (name, image_path, price, type, sold, stock, detail, seller_id, status) " +
            "VALUES (#{name}, #{imagePath}, #{price}, #{type},#{sold}, #{stock}, #{detail}, #{sellerId}, #{status})")
    void insertProduct(Product product);

    @Update("UPDATE tb_product SET name = #{name}, image_path = #{imagePath}, price = #{price}, type = #{type},  stock = #{stock}, detail = #{detail} WHERE id = #{id}")
    void update(Product product);

}

